package cn.gson.springboot.controller.aftercontroller;

import cn.gson.springboot.aop.MyLog;
import cn.gson.springboot.model.pjos.Culog;
import cn.gson.springboot.model.service.afterservice.CulogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/log")
public class CulogController {

    @Autowired
    CulogService sc;

    @RequestMapping("/clog-page")
    @ResponseBody
    public Map<String,Object> clogPage(Integer userName, Integer fatherDeptId, Integer logType, String title, Integer currPage, Integer pageSize) {
        Page<Object> obj = PageHelper.startPage(currPage, pageSize);
        List<Culog> log = sc.selectCulogPage(userName, fatherDeptId, logType, title);

        Map<String, Object> map = new HashMap<>();
        map.put("rows", obj.getResult());        //分页后的数据，一页展示多少数据
        map.put("total", obj.getTotal());        //总条数
        return map;
    }

    @MyLog(type = "日志",value = "新增了日志")
    @RequestMapping("/save-log")
    @ResponseBody
    public void saveLog(@RequestBody Culog log){
        sc.addLog(log);
    }

    @RequestMapping("/delete-log")
    @ResponseBody
    public void deleteLog(String deleteId){
        sc.delete(deleteId);
    }

    @RequestMapping("/check-log")
    @ResponseBody
    public Culog checkLog(Integer culId){
        return sc.selectByCulId(culId);
    }
}
